<?php
namespace Tools;



//新建一个真彩色图像
      $image = imagecreatetruecolor(140,40);

 //验证图随机数字
      $charset = 'abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ23456789';

 //设置背景颜色和字体颜色
      $bg = imagecolorallocate($image,243, 251, 254);
      imagefill($image,0,0,$bg);
      $ft = imagecolorallocate($image,0,0,0);

 //验证码随机颜色
      $_color = imagecolorallocate($image, mt_rand(1,120), mt_rand(1,120), mt_rand(1,120));

 //验证码
        $code = array(); // 验证码
        $code_num = "";
        $codeNX = 0; // 验证码第N个字符的左边距
        for ($i = 0; $i<4; $i++) {
            $code[$i] =$charset[mt_rand(0, 49)];
            $code_num.=$code[$i];
            $codeNX += mt_rand(15,25);
            // 写一个验证码字符
            imagettftext($image,20,mt_rand(-10,30),$codeNX,22,$_color, "../ttf/simhei.ttf", $code[$i]);
        }
         $_SESSION['check_pic'] = $code_num;

 //干扰线
     for($n=1;$n<=4;$n++){
 	   $color = imagecolorallocate($image,rand(0,255),rand(0,255),rand(0,255));
       imageline($image,0,rand(0,30),100,rand(0,30),$color);
 }

 //干扰点
     for($j=1;$j<=1000;$j++){
 	    imagesetpixel($image,rand(0,255),rand(0,255),$color);
 }

 //输出图像
 header("Content-type:image/jpeg");
 imagejpeg($image);


?>
